from itertools import accumulate

# 求总重量不超过c的装载最大数量
def maxLoading(w: list[int], c: int) -> int:
    n = 0
    for l in accumulate(sorted(w)):
        if l > c: 
            break
        n += 1
    return n

# 进阶：一行代码完成
def maxLoading_OneLine(w: list[int], c: int) -> int:
    return max(i + 1 if l <= c else 0 for i, l in enumerate(accumulate(sorted(w))))

